import {fetchList, delObj} from '@/views/client-manage/api/clientlessee'
import clientExport from '@/views/client-manage/components/client-export.vue'
// hxf-0805-引入校验字段名混合
import EditBase from '@/assets/vue-mixin/EditBase'
import {getDict} from "~/utils";
// hxf-0806-引入loading混合
import BaseLoad from '@/assets/vue-mixin/BaseLoad'
import pager from '@/assets/vue-mixin/pager'
import {mapState} from 'vuex'

export default {
    name: "new-reimbursement",
    mixins: [pager,EditBase,BaseLoad],
    components: {
        clientExport
    },
    computed:
        mapState({
            //客户类型
            lessee_type: state => {
                let data = state.dict.find(item => item.type === "lessee_type") || {};
                //let list = data.children || []
                return data.children || []
            },
        }),
    mounted() {
        //获取数据字段的值
        this.totalSearchData[0].children=this.lessee_type;
        // console.log(this.approve_template);
    },
    data()  {
        return {
            tableData: [],
            lesseeTypeList: [],
            searchForm: {
            },
            totalSearchData: [
                {
                    label: '客户类型',
                    value: 'type',
                    type: 'select',
                    model: 'type',
                    children: []
                }
            ],
            searchDataFrom: {
            },
            timeData:[],
            placeholder:'请输入客户名称'
        }
    },

    methods: {
        lessee_type_list: function(row, column, cellValue){
            let obj = this.lessee_type.find(p => p.value == cellValue )
            if(obj){
                return obj.label
            }
            return ''
        },
        getListData(){
            fetchList(Object.assign({},this.pageParams,this.searchForm)).then(response=>{
                this.setListData(response.data)
            }).catch(()=>{
                console.log("catch")
            })
        },
        searchByKey(val) {
            // console.log('searchByKey', this.searchDataFrom);
            //获取输入的值
            if(val){
                this.searchForm.clientLesseeName=val;
            }else {
                delete this.searchForm.clientLesseeName
            }
            if(this.searchDataFrom.type){
                let sum=[]
                this.searchDataFrom.types.map(item =>{
                    sum.push(item.value)
                })
                this.searchForm.clientLesseeTypes=sum
            }
            this.resetList()
        },
        //qh+：点击编辑跳转到新的页面
        toEdit(row) {
            this.$router.push({path:"/client-manage/lessee-manage/edit?id="+row.clientLesseeId})
        },
        //qh+:点击查看跳转到查看页面
        toAdd() {
            this.$router.push({path:"/client-manage/lessee-manage/add"})
        },
        toImport(){
            this.$router.push({path:"/client-manage/lessee-manage/import"})
        },
        //qh+:点击名称跳转
        toPerson(row){
            //点击列表页名称跳转
            this.$router.push({path:"/client-manage/lessee-manage/look?id="+row.clientLesseeId})
        },
        //qh+:显示导出弹出框
        toExport(){
          this.$refs.clientExport.show()
        },

        //qh+：重置
        searchReset() {
            // console.log("====searchReset")
            //清空选中的数据
            this.searchForm = {}
            //重新查询
            this.resetList()
        },
        rowDel(row){
            //取出数据，由于字段名不一样，需要创建一个对应实体类表字段名的对象作为参数
            //也可以直接obj=row
            var obj={};
            //obj.clientLesseeId=row.clientLesseeId;
            this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //删除
                delObj(row.clientLesseeId).then(response => {
                    this.resetList()
                })

                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
    }
}
